import { ApiProperty } from "@nestjs/swagger";
import { IsEnum, IsInt, IsOptional, IsString, MaxLength } from "class-validator";
import { PointRuleRewardType, PointRuleType } from "./points-rules.entity";
import { Type } from "class-transformer";

export class CreatePointsRulesDto {

	@ApiProperty({description: '积分规则名称', default: ''})
	@IsString()
	@MaxLength(50)
	ruleName: string;

	@ApiProperty({description: '积分规则描述', required: false})
	@IsOptional()
	@IsString()
	@MaxLength(200)
	ruleDescription?: string;

	@ApiProperty({description: '积分规则类型', default: PointRuleType.FIXED})
	@IsEnum(PointRuleType)
	ruleType: PointRuleType

	@ApiProperty({description: '积分发放类型', default: PointRuleRewardType.PER_ATTEMPT, required: false})
	@IsOptional()
	@IsEnum(PointRuleRewardType)
	rewardType?: PointRuleRewardType

	@ApiProperty({description: '需要完成的次数'})
	@IsInt()
	@Type(() => Number)
	targetCount: number;

	@ApiProperty({description: '固定积分值'})
	@IsInt()
	@Type(() => Number)
	fixedPoints: number; // 固定积分值（仅适用于 fixed 规则）
}

export class UpdatePointsRulesDto {
	@ApiProperty({description: '积分规则名称', required: false})
	@IsOptional()
	@IsString()
	@MaxLength(50)
	ruleName?: string;

	@ApiProperty({description: '积分规则描述', required: false})
	@IsOptional()
	@IsString()
	@MaxLength(200)
	description?: string;

	@ApiProperty({description: '需要完成的次数', required: false})
	@IsOptional()
	@IsInt()
	@Type(() => Number)
	targetCount?: number;

	@ApiProperty({description: '固定积分值', required: false})
	@IsOptional()
	@IsInt()
	@Type(() => Number)
	fixedPoints?: number; // 固定积分值（仅适用于 fixed 规则）
}